<template>
  <div>
    <van-nav-bar title="登录" left-text="返回" left-arrow @click-left="onClickLeft"></van-nav-bar>
    <van-image class="imgs" width="350" height="250" src="bimg/ttk.png" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        center clearable 
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ pattern, message: '用户名最少6位数' }]"
      />
      <van-field
        v-model="password"
        center clearable 
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ pattern, message: '请输入最少6位数密码' }]"
      />

      <!-- <van-field 
        v-model="sms" 
        center clearable 
        label="邮箱验证码" 
        placeholder="请输入邮箱验证码"  
        name="sms"
        @blur="blur"
        :rules="[{ required:true,message: '请输入正确邮箱验证码' }]"
      >
     
        <template #button>
          <van-button size="small" type="primary" @click="sendsms">发送验证码</van-button>
        </template>
      </van-field>
       <div v-if="show" style="color:red; margin-left:20px;">
        <span>
        请输入正确邮箱验证码
        </span>
      </div> -->

      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit" :disabled='shows'>登录</van-button>
      </div>
      <div class="bottom">
        <span>
          还没有账号？
          <i class="register" @click="zhuce">注册</i>
        </span>
        <span class="forgetpass">
           <i class="register" @click="forget">忘记密码</i>
          
        </span>
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "",
      password: "",
      img: "bimg/ttk.png",
      pattern: /[a-zA-Z0-9]{6,15}$/,
      patterns:'',
      sms:'',
      youxiang:'',
      show:false,
      shows:false
    };
  },
  methods: {
    onSubmit(values) {
      console.log("submit", values);
      this.$axios.post("/api/user", values).then((data) => {
        console.log(data);
        if (data.data.code == 200) {
          console.log(data)
          alert(data.data.msg);
          this.$router.push("/personal");
          var sh = data.data.shop[0].cart;
          sh = JSON.parse(sh);
          var ch = JSON.parse(data.data.shop[0].collection);
          console.log(ch.collection);
          console.log(sh.shop);
          localStorage.setItem("bookh", JSON.stringify(sh.shop));
          localStorage.setItem("bookx", JSON.stringify(ch.collection));
          // console.log(data.data.shop[0].cart);
          localStorage.setItem("key", JSON.stringify(values));
        } else if(data.data.code == 300) {
          alert(data.data.msg);
        }else{
          alert(data.data.msg);
          this.$router.push("/zhuce");
        }
      });
      localStorage.setItem("key", JSON.stringify(values));
    },
    onClickLeft() {
      this.$router.push("/Home");
    },
    zhuce() {
      this.$router.push("/zhuce");
    },
    forget(){
      this.$router.push("/forget");
    },
  
  },
};
</script>

<style lang="stylus" scoped>
.imgs {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
  margin: 0 auto;
}
.qqw{
  color :red;
  height :200px;
}
.register {
  color: blue;
}

.bottom {
  display :flex;
  width: 100%;
  justify-content:space-around;
  position: relative;
  top:.2rem;
}
.forgetpass{
  color :red;
}
.van-cell{
  line-height: 16px;
  height: 56px;
}
</style>